<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="shortcut icon" href="img/favicon.ico" type="images/x-icon" />
    <title>登录注册表</title>
    <script src="../dist/demo.bundle.js"></script>
</head>

<body>
    <div class="htmleaf-container">
        <div id="wrapper" class="login-page">
            <div class="form">
                <form class="register-form" id="register_form">
                    <span id="r_error" class="error_message"></span>
                    <input type="text" placeholder="用户名" id="r_user_name" name="r_user_name" />
                    <input type="password" placeholder="密码" id="r_password" name="r_password" />
                    <input type="text" placeholder="电子邮件" id="r_email" name="r_email" />
                    <input type="hidden" name="myrequest" value="regestUser">
                    <button id="create">创建账户</button>
                    <p class="message">已经有了一个账户? <a href="#">立刻登录</a></p>
                </form>
                <form class="login-form" id="login_form">
                    <span id="l_error" class="error_message"></span>
                    <input type="text" placeholder="用户名" name="user_name" id="user_name" />
                    <input type="password" placeholder="密码" name="user_pass" id="user_pass" />
                    <input type="hidden" name="myrequest" value="login">
                    <button id="login">登　录</button>
                    <p class="message">还没有账户? <a href="#">立刻创建</a></p>
                </form>
            </div>
        </div>
    </div>
    <script src="https://cdn.staticfile.net/jquery/1.10.2/jquery.min.js"></script>
    <script type="text/javascript">
        var registUrl = "fileUserServlet";
        var loginUrl = "/api/login";
        /**
         * 登录
         */
        function login() {
            let user_name = $("#user_name").val();
            let user_pass = $("#user_pass").val();
            // 登录
            $.post(loginUrl, {
                username: user_name,
                password: user_pass
            }, function (data) {
                alert(JSON.parse(data).msg)
            })
        }

        /**
         * 创建用户（请补全缺失的代码）
         */
        function register() {

        }

        $(function () {
            //创建用户
            $("#create").click(function () {
                register();
                return false;
            })
            //登录
            $("#login").click(function () {
                login();
                return false;
            })
            //切换登录注册表单
            $('.message a').click(function () {
                $('form').animate({
                    height: 'toggle',
                    opacity: 'toggle'
                }, 'slow');
            });
        })
    </script>
</body>

</html>